let that = null
Page({
    data: {
        show: false,
        name: '',
        tel: '',
        LogCompany: '',
        odd: '',
        disabled: false,
        beforeClose: (action) => new Promise((resolve) => {
            if (action === 'confirm') {
                let $this = that.data
                if (!$this.name) {
                    wx.showToast({
                        title: '请输入发货人姓名',
                        icon: 'none'
                    })
                    return resolve(false)
                }
                if (!$this.tel) {
                    wx.showToast({
                        title: '请输入发货人手机号',
                        icon: 'none'
                    })
                    return resolve(false)
                }
                if ($this.tel) {
                    const reg = /^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$/
                    if (!reg.test($this.tel)) {
                        wx.showToast({
                            title: '请输入正确的手机号码',
                            icon: 'none'
                        })
                        return resolve(false)
                    }
                }
                if (!$this.LogCompany) {
                    wx.showToast({
                        title: '请输入物流公司',
                        icon: 'none'
                    })
                    return resolve(false)
                }
                if (!$this.odd) {
                    wx.showToast({
                        title: '请输入物流单号',
                        icon: 'none'
                    })
                    return resolve(false)
                }
                if (!/^[A-Za-z0-9]+$/.test($this.odd)) {
                    wx.showToast({
                        title: '物流单号为数字和字母',
                        icon: 'none'
                    })
                    return resolve(false)
                }
                that.setData({ disabled: true })
                //点击提交，发请求，请求成功之后resolve关闭弹窗
                setTimeout(() => {
                    resolve(true);
                    // that.setData({disabled : false})
                    wx.showToast({
                        title: '提交成功',
                        icon: 'success'
                    })
                    wx.redirectTo({
                        url: '/pages/store_orderDetailOk/detail',
                    })
                }, 3000)
            } else {
                resolve(true)
            }
        })
    },
    onLoad() {
        that = this
    },
    //展示提交地址弹出框
    submit_logisticsInfo() {
        this.setData({ show: true });
    },
    onUnload: function() {
        that = null
    }
})